package ai.bussness;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;


/**
 * Created by 杨济瑞 on 2016/8/9.
 */

public class DBOperation {
    Connection conn;

    /**
     * 通用的链接数据库方法
     *
     * @return 一个链接对象
     */
    public Connection getConnection() {

        String url = "jdbc:mysql://localhost:3306/yangjirui?"
                + "user=root&password=320925&useUnicode=true&characterEncoding=UTF8";
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("not found driver");
            e.printStackTrace();
        }
        try {
            conn = DriverManager.getConnection(url);
            if (conn != null) {
//                System.out.println("connection successful~~~~");
            }
        } catch (SQLException e) {
            System.out.println("connection fail!!!!");
            e.printStackTrace();
        }
        return conn;
    }
}
